#ifndef IMAGE_AXIS_H
#define IMAGE_AXIS_H

/**
 * qml cpp自定义组件，坐标轴
 * !!!!!!!!!!!
 * TODO:: 调整vertial的tick偏差，实现text font大小自适应width、height、tick_num
 *  ------------根据axis_length_以及tick_num_计算出合适的font大小
 *  ------------或许也可以计算出合适的width大小
 */

#include <QObject>
#include <QQuickPaintedItem>

namespace solar
{
    class ImageAxis : public QQuickPaintedItem
    {
            Q_OBJECT

            Q_PROPERTY(bool item_visible MEMBER visible_ NOTIFY visibleChanged)
            Q_PROPERTY(bool horizontal MEMBER horizontal_ NOTIFY horizontalChanged)
            Q_PROPERTY(int tick_num MEMBER tick_num_ NOTIFY tickNumChanged)
            Q_PROPERTY(float min_tick MEMBER min_tick_ NOTIFY minTickChanged)
            Q_PROPERTY(float max_tick MEMBER max_tick_ NOTIFY maxTickChanged)
            Q_PROPERTY(int axis_length MEMBER axis_length_ NOTIFY axisLengthChanged)
            Q_PROPERTY(int font_size MEMBER font_size_ NOTIFY fontSizeChanged)

            Q_PROPERTY(int offset MEMBER offset_)

            QML_ELEMENT

        public:
            ImageAxis(QQuickItem* parent = nullptr);
            ~ImageAxis() override = default;

            void paint(QPainter* painter) override;
            void paintHorizontalAxis(QPainter* painter);
            void paintVerticalAxis(QPainter* painter);

        signals:
            void visibleChanged();
            void horizontalChanged();
            void tickNumChanged();
            void minTickChanged();
            void maxTickChanged();
            void axisLengthChanged();
            void fontSizeChanged();

        public slots:
            Q_INVOKABLE void rePaint();

        private:
            bool visible_{false}; // 是否可见

            bool horizontal_{true}; // 是否是水平方向的坐标轴

            int tick_num_{11};                // 标签数目
            float min_tick_{0}, max_tick_{1}; // 最小最大的标签值
            int axis_length_{50};             // 坐标轴的长度
            int offset_{0}; // 为了让标签内容显示完全，设置x、y、width、height时需要考虑一个偏移量
            int font_size_{8}; // 标签字体大小
    };
} // namespace solar

#endif
